package com.xuecheng.content.agent.hystrix;

import com.xuecheng.api.system.model.dto.CourseCategoryDTO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.hystrix.BaseAPIHystrix;
import com.xuecheng.common.hystrix.BaseFallbackFactory;
import com.xuecheng.content.agent.SystemApiAgent;
import org.springframework.stereotype.Component;

/**
 * Created on 2021/04/05/19:53 周一
 *
 * @author Lantin
 */

@Component
public class SystemApiAgentFallbackFactory extends BaseFallbackFactory<
        BaseAPIHystrix,
        SystemApiAgentFallbackFactory.SystemApiAgentHystrix,
        SystemApiAgentFallbackFactory.DevSystemApiAgentHystrix> {

    /**
     * <p>
     * 生产环境降级方法类
     * </p>
     * 返回
     */
    public static class SystemApiAgentHystrix extends BaseAPIHystrix<CourseCategoryDTO> implements SystemApiAgent {

        public SystemApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<CourseCategoryDTO> getCourseCategoryById(String id) {
            return baseFailResult();
        }
    }


    /**
     * <p>
     * 开发环境降级方法类
     * </p>
     * 返回一个默认值
     */
    public static class DevSystemApiAgentHystrix extends BaseAPIHystrix<CourseCategoryDTO> implements SystemApiAgent {

        public DevSystemApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<CourseCategoryDTO> getCourseCategoryById(String id) {
            return RestResponse.success(new CourseCategoryDTO());
        }
    }
}
